
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 04/22/2014 12:12:29
-- Generated from EDMX file: C:\Users\Jos\Documents\webtv-project\Kickstarter\EFDataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [WEBTV];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserDonation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DonationSet] DROP CONSTRAINT [FK_UserDonation];
GO
IF OBJECT_ID(N'[dbo].[FK_UserProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectSet] DROP CONSTRAINT [FK_UserProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectEvent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventSet] DROP CONSTRAINT [FK_ProjectEvent];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectGoal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GoalSet] DROP CONSTRAINT [FK_ProjectGoal];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRating]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RatingSet] DROP CONSTRAINT [FK_UserRating];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectRating]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RatingSet] DROP CONSTRAINT [FK_ProjectRating];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectMessage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MessageSet] DROP CONSTRAINT [FK_ProjectMessage];
GO
IF OBJECT_ID(N'[dbo].[FK_GebruikerMessage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MessageSet] DROP CONSTRAINT [FK_GebruikerMessage];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectDonation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DonationSet] DROP CONSTRAINT [FK_ProjectDonation];
GO
IF OBJECT_ID(N'[dbo].[FK_AnoDonationProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnoDonationSet] DROP CONSTRAINT [FK_AnoDonationProject];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[GebruikerSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GebruikerSet];
GO
IF OBJECT_ID(N'[dbo].[DonationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DonationSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSet];
GO
IF OBJECT_ID(N'[dbo].[EventSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventSet];
GO
IF OBJECT_ID(N'[dbo].[GoalSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GoalSet];
GO
IF OBJECT_ID(N'[dbo].[RatingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RatingSet];
GO
IF OBJECT_ID(N'[dbo].[MessageSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MessageSet];
GO
IF OBJECT_ID(N'[dbo].[AnoDonationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnoDonationSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'GebruikerSet'
CREATE TABLE [dbo].[GebruikerSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(200)  NOT NULL,
    [Place] nvarchar(max)  NOT NULL,
    [Adress] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Company] nvarchar(max)  NULL,
    [isAdmin] bit  NULL,
    [TotalDonated] int  NULL,
    [Wachtwoord] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'DonationSet'
CREATE TABLE [dbo].[DonationSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] int  NOT NULL,
    [UserId] int  NOT NULL,
    [ProjectId] int  NOT NULL
);
GO

-- Creating table 'ProjectSet'
CREATE TABLE [dbo].[ProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [TotalAmount] int  NOT NULL,
    [TotalRating] int  NOT NULL,
    [UserId] int  NOT NULL,
    [NumberOfVotes] int  NOT NULL,
    [NumberOfMessages] int  NOT NULL
);
GO

-- Creating table 'EventSet'
CREATE TABLE [dbo].[EventSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MinimumAmount] int  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [ProjectId] int  NOT NULL
);
GO

-- Creating table 'GoalSet'
CREATE TABLE [dbo].[GoalSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Amount] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [isAchieved] bit  NOT NULL,
    [ProjectId] int  NOT NULL
);
GO

-- Creating table 'RatingSet'
CREATE TABLE [dbo].[RatingSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Score] int  NOT NULL,
    [UserId] int  NOT NULL,
    [ProjectId] int  NOT NULL
);
GO

-- Creating table 'MessageSet'
CREATE TABLE [dbo].[MessageSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Context] nvarchar(max)  NOT NULL,
    [ProjectId] int  NOT NULL,
    [GebruikerId] int  NOT NULL
);
GO

-- Creating table 'AnoDonationSet'
CREATE TABLE [dbo].[AnoDonationSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] int  NOT NULL,
    [ProjectId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'GebruikerSet'
ALTER TABLE [dbo].[GebruikerSet]
ADD CONSTRAINT [PK_GebruikerSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DonationSet'
ALTER TABLE [dbo].[DonationSet]
ADD CONSTRAINT [PK_DonationSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [PK_ProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EventSet'
ALTER TABLE [dbo].[EventSet]
ADD CONSTRAINT [PK_EventSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'GoalSet'
ALTER TABLE [dbo].[GoalSet]
ADD CONSTRAINT [PK_GoalSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RatingSet'
ALTER TABLE [dbo].[RatingSet]
ADD CONSTRAINT [PK_RatingSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MessageSet'
ALTER TABLE [dbo].[MessageSet]
ADD CONSTRAINT [PK_MessageSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AnoDonationSet'
ALTER TABLE [dbo].[AnoDonationSet]
ADD CONSTRAINT [PK_AnoDonationSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserId] in table 'DonationSet'
ALTER TABLE [dbo].[DonationSet]
ADD CONSTRAINT [FK_UserDonation]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[GebruikerSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserDonation'
CREATE INDEX [IX_FK_UserDonation]
ON [dbo].[DonationSet]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [FK_UserProject]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[GebruikerSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserProject'
CREATE INDEX [IX_FK_UserProject]
ON [dbo].[ProjectSet]
    ([UserId]);
GO

-- Creating foreign key on [ProjectId] in table 'EventSet'
ALTER TABLE [dbo].[EventSet]
ADD CONSTRAINT [FK_ProjectEvent]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectEvent'
CREATE INDEX [IX_FK_ProjectEvent]
ON [dbo].[EventSet]
    ([ProjectId]);
GO

-- Creating foreign key on [ProjectId] in table 'GoalSet'
ALTER TABLE [dbo].[GoalSet]
ADD CONSTRAINT [FK_ProjectGoal]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectGoal'
CREATE INDEX [IX_FK_ProjectGoal]
ON [dbo].[GoalSet]
    ([ProjectId]);
GO

-- Creating foreign key on [UserId] in table 'RatingSet'
ALTER TABLE [dbo].[RatingSet]
ADD CONSTRAINT [FK_UserRating]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[GebruikerSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRating'
CREATE INDEX [IX_FK_UserRating]
ON [dbo].[RatingSet]
    ([UserId]);
GO

-- Creating foreign key on [ProjectId] in table 'RatingSet'
ALTER TABLE [dbo].[RatingSet]
ADD CONSTRAINT [FK_ProjectRating]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectRating'
CREATE INDEX [IX_FK_ProjectRating]
ON [dbo].[RatingSet]
    ([ProjectId]);
GO

-- Creating foreign key on [ProjectId] in table 'MessageSet'
ALTER TABLE [dbo].[MessageSet]
ADD CONSTRAINT [FK_ProjectMessage]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectMessage'
CREATE INDEX [IX_FK_ProjectMessage]
ON [dbo].[MessageSet]
    ([ProjectId]);
GO

-- Creating foreign key on [GebruikerId] in table 'MessageSet'
ALTER TABLE [dbo].[MessageSet]
ADD CONSTRAINT [FK_GebruikerMessage]
    FOREIGN KEY ([GebruikerId])
    REFERENCES [dbo].[GebruikerSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GebruikerMessage'
CREATE INDEX [IX_FK_GebruikerMessage]
ON [dbo].[MessageSet]
    ([GebruikerId]);
GO

-- Creating foreign key on [ProjectId] in table 'DonationSet'
ALTER TABLE [dbo].[DonationSet]
ADD CONSTRAINT [FK_ProjectDonation]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectDonation'
CREATE INDEX [IX_FK_ProjectDonation]
ON [dbo].[DonationSet]
    ([ProjectId]);
GO

-- Creating foreign key on [ProjectId] in table 'AnoDonationSet'
ALTER TABLE [dbo].[AnoDonationSet]
ADD CONSTRAINT [FK_AnoDonationProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnoDonationProject'
CREATE INDEX [IX_FK_AnoDonationProject]
ON [dbo].[AnoDonationSet]
    ([ProjectId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------